﻿/* !
 *  图片滚动 
 */
var imgscroll = {};
imgscroll.runing = 0;
imgscroll.effect1 = function (cindex) {
    var index;
    if (cindex) {
        index = cindex;
    }
    else {
        index = 0;
    }
    var len = $("#sliderNav li").length;
    if (len == 0) {
        return;
    }
    var sliderTimer;
    var bigNav = $(".bigpic_nav").width();
    var page = 1;
    var i = 6;
    var offset = ($("#sliderNav li").width() + parseInt($("#sliderNav li").css("margin-right"))) * i;
    var boxWidth = $("#sliderBox li").width() * $("#sliderBox li").length;
    var navWidth = ($("#sliderNav li").width() + parseInt($("#sliderNav li").css("margin-right"))) * $("#sliderNav li").length;
    $("#sliderBox ul").css("width", boxWidth);
    $("#sliderNav ul").css("width", navWidth);

    $("#sliderNav li").click(function () {
        var index2 = $("#sliderNav li").index(this);
        showImg(index2);
        index = index2;
    }).eq(0).mouseover();
    var pagecount = Math.ceil(navWidth / $("#sliderNav").width());
    /*	$("#sliderBox").hover(function(){
            clearInterval(sliderTimer);
            },function(){
                sliderTimer = setInterval(function(){
                    showImg(index);
                    index++;
                    if(index==len){
                        index = 0;
                        showImg(index);
                        }
                    },3000)
                }).trigger("mouseleave");*/
    $("#bigprev,#picleft").unbind();
    $("#bigprev,#picleft").click(function () {
        if (index == 0) {
            return;
        }
        index -= 1;
        showImg(index);

    })
    $("#bignext,#picright").unbind();
    $("#bignext,#picright").click(function () {
        if (index == (len - 1)) {
            return;
        }
        index += 1;
        showImg(index);


    });
    $(".prev-nav").unbind();
    $(".prev-nav").click(function () {
        if (imgscroll.runing) {
            return null;
        }
        var minleft = $("#sliderNav").offset().left;
        var firstleft = $("#sliderNav li").eq(0).offset().left;

        if (firstleft >= minleft) {
            return false;
        } else {
            $("#sliderNav ul").stop(true, true).animate({ left: '+=' + offset }, 1000);
        }
        imgscroll.runing = 1;
        setTimeout("imgscroll.runing=0", 1000);
    });
    $(".next-nav").unbind();
    $(".next-nav").click(function () {
        if (imgscroll.runing) {
            return null;
        }
        var maxleft = $("#sliderNav").offset().left + $("#sliderNav").width();
        var lastleft = $("#sliderNav li").eq($("#sliderNav li").length - 1).offset().left;

        if (lastleft <= maxleft) {
            return false;
        } else {
            $("#sliderNav ul").stop(true, true).animate({ left: '-=' + offset }, 1000);
        }
        imgscroll.runing = 1;
        setTimeout("imgscroll.runing=0", 1000);
    });

    function showImg(index) {
        imgscroll.showImg(index, 1000);
    }
}
imgscroll.showImg = function (index, speed) {
    var imgWidth = $("#sliderBox li").width();
    var liWidth = $("#sliderNav li").width();
    $("#sliderBox ul").stop(true, false).animate({ left: -imgWidth * index }, speed);
    $("#sliderNav li").removeClass("current").eq(index).addClass("current");
    var currentimg = $("#sliderNav li").eq(index);
    $("#phototype").html(currentimg.attr("PhotoType"));
    $("#photoindex").html(index + 1);
    $("#imgcreator").html(currentimg.attr("creator"));
    var PhotoComment = currentimg.attr("PhotoComment");
    if (PhotoComment && PhotoComment != "undefined") {
        $("#PhotoComment").html(PhotoComment + "&nbsp;");
    }

    //重置图片卷轴的位置
    $("#sliderNavul").css("left", 0);

    var newleft = $("#sliderNav li").eq(index).offset().left;
    var maxleft = $("#sliderNav").offset().left + $("#sliderNav").width();
    var minleft = $("#sliderNav").offset().left;

    var temoffset = (parseInt((index) / 6)) * 6 * 131;
    //$("#sliderNav ul").stop(true, true).animate({ left: '-=' + temoffset }, speed);
    $("#sliderNav ul").css("left", 0 - temoffset);

}

imgscroll.supeffect1 = function(cindex) {
    var index;
    if (cindex) {
        index = cindex;
    } else {
        index = 0;
    }
    var len = $("#supsliderNav li").length;
    if (len == 0) {
        return;
    }
    var i = 6;
    var offset = ($("#supsliderNav li").height() + parseInt($("#supsliderNav li").css("margin-bottom"))) * i;
    var boxWidth = $("#supsliderBox li").height() * $("#supsliderBox li").length;
    var navWidth = ($("#supsliderNav li").height() + parseInt($("#supsliderNav li").css("margin-bottom"))) * $("#supsliderNav li").length;
    $("#supsliderBox ul").css("height", boxWidth);
    $("#supsliderNav ul").css("height", navWidth);

    $("#supsliderNav li").click(function() {
        var index2 = $("#supsliderNav li").index(this);
        showImg(index2);
        index = index2;
    }).eq(0).mouseover();
    var pagecount = Math.ceil(navWidth / $("#supsliderNav").height());
    /*	$("#supsliderBox").hover(function(){
            clearInterval(sliderTimer);
            },function(){
                sliderTimer = setInterval(function(){
                    showImg(index);
                    index++;
                    if(index==len){
                        index = 0;
                        showImg(index);
                        }
                    },3000)
                }).trigger("mouseleave");*/
    $("#bigprev,#picleft").unbind();
    $("#bigprev,#picleft").click(function() {
        if (index == 0) {
            return;
        }
        index -= 1;
        showImg(index);
    });
    $("#bignext,#picright").unbind();
    $("#bignext,#picright").click(function() {
        if (index == (len - 1)) {
            return;
        }
        index += 1;
        showImg(index);
    });
    $(".super-prev-nav").unbind();
    $(".super-prev-nav").click(function() {
        if (imgscroll.runing) {
            return null;
        }
        var minleft = $("#supsliderNav").offset().top;
        var firstleft = $("#supsliderNav li").eq(0).offset().top;

        if (firstleft >= minleft) {
            return false;
        } else {
            $("#supsliderNav ul").stop(true, true).animate({ top: '+=' + offset }, 1000);
        }
        imgscroll.runing = 1;
        setTimeout("imgscroll.runing=0", 1000);
    });
    $(".super-next-nav").unbind();
    $(".super-next-nav").click(function() {
        if (imgscroll.runing) {
            return null;
        }
        var maxleft = 825;
        var lastleft = $("#supsliderNav li").eq($("#supsliderNav li").length - 1).offset().top;
        if (lastleft <= maxleft) {
            return false;
        } else {
            $("#supsliderNav ul").stop(true, true).animate({ top: '-=' + offset }, 1000);
        }
        imgscroll.runing = 1;
        setTimeout("imgscroll.runing=0", 1000);
    });

    function showImg(index) {
        imgscroll.supshowImg(index, 1000);
    }
};
imgscroll.supshowImg = function (index, speed) {
     var imgWidth = $("#supsliderBox li").height();
     $("#supsliderBox ul").stop(true, false).animate({ top: -imgWidth * index }, speed); 
     $("#supsliderNav li").removeClass("current").eq(index).addClass("current");
     var currentimg = $("#supsliderNav li").eq(index);
     $("#supphototype").html(currentimg.attr("PhotoType"));
     $("#supphotoindex").html(index + 1);
     $("#supimgcreator").html(currentimg.attr("creator"));
     var PhotoComment = currentimg.attr("PhotoComment");
     if (PhotoComment && PhotoComment != "undefined") {
         $("#PhotoComment").html(PhotoComment + "&nbsp;");
     }
     //重置图片卷轴的位置
     $("#sliderNavul").css("top", 0);
 }